﻿using ERP_SaaS_WinForm.登录.Common;
using ERP_SaaS_WinForm.登录.Model;
using ERP_SaaS_WinForm.销售;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_SaaS_WinForm.登录
{
    public partial class AddCheckWork : Form
    {
        public AddCheckWork()
        {
            InitializeComponent();
        }
        private HttpClient httpClient = new HttpClient();
        public async void AddCheckWorks()
        {
            string url = "http://10.223.8.3:8077/api/CheckProductWork/AddCheckProductWork";
            var updateData = new
            {
                CheckProductWork_Id = 0,
                ProductName = textcheck.Text.Trim(),
                ProductCode = textcode.Text.Trim(),
                CheckType = checktype.Text.Trim(),
                CheckMethod = checkmethod.Text.Trim(),
                CheckRequire = checkrequer.Text.Trim(),
                CheckUnit = textserious.Text.Trim(),
                FatalFlaw = textflaw.Text.Trim(),
                SeriousDefects = textserious.Text.Trim(),
                MinorDefects = textsimple.Text.Trim(),
                Markes = textmartk.Text.Trim(),
                IsDel = false
            };

            var json = JsonConvert.SerializeObject(updateData);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                var response = await httpClient.PostAsync(url, content);
                response.EnsureSuccessStatusCode();

                string jsonResponse = await response.Content.ReadAsStringAsync();
                MessageBox.Show("添加成功！");
            }
            catch (HttpRequestException ex)
            {
                MessageBox.Show($"请求出错: {ex.Message}");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"发生错误: {ex.Message}");
            }
        }
        private void txtadd_Click(object sender, EventArgs e)
        {
            AddCheckWorks();
        }

        private void AddCheckWork_Load(object sender, EventArgs e)
        {

        }
    }
}
